package idv.jieh.web;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class EncodingServlet extends HttpServlet implements Filter {
  private FilterConfig filterConfig;

  public void init(FilterConfig filterConfig) throws ServletException {
    this.filterConfig = filterConfig;
  }

  public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) {
    String code = filterConfig.getInitParameter("encoding");
    try {
      request.setCharacterEncoding(code);
      filterChain.doFilter(request, response);
    } catch (ServletException sx) {
      filterConfig.getServletContext().log(sx.getMessage());
    } catch (IOException iox) {
      filterConfig.getServletContext().log(iox.getMessage());
    }
  }

} // end class EncodingServlet
